package com.chengsi.controller;

import com.chengsi.pojos.Chengsi;
import com.chengsi.pojos.Student;
import com.chengsi.result.RequestResult;
import com.chengsi.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentServive;

    @GetMapping("/{studentId}")
    public RequestResult<Student> getStudentById(@PathVariable Integer studentId){
        Student student = studentServive.getStudentById(studentId);
        return RequestResult.success(student);
    }

    @PostMapping
    public RequestResult<Boolean> addStudent(Student student){
        return RequestResult.success(studentServive.insertStudent(student));
    }

    @PutMapping
    public RequestResult<Boolean> updateStudent(Student student){
        return RequestResult.success(studentServive.updateStudent(student));
    }

    @DeleteMapping
    public RequestResult<Boolean> deleteStudent(Integer studentId){
        return RequestResult.success(studentServive.deleteStudent(studentId));
    }

    @GetMapping("/chengsi")
    public RequestResult<Chengsi> getChengsi(){
        return RequestResult.success(studentServive.getPersonalInfo());
    }


}
